package com.systop.dxjj.modules.user.service.impl;

import com.systop.dxjj.common.pojo.User;
import com.systop.dxjj.common.pojo.Useruse;
import com.systop.dxjj.modules.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service("userDetailsService")
public class UserDetailsServices implements UserDetailsService {
    @Autowired
    UserMapper userMapper;

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //调用studentMapper方法，根据用户名查询数据库
        User user = userMapper.selectUserByName(username);
        //判断
        if (user == null) {
            throw new UsernameNotFoundException("用户名不存在！");
        }

        //把数据封装成UserDetails返回
        return new Useruse(user);
    }
}
